<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="整车物料号:" prop="materialNo">
          <el-input v-model="formModel.materialNo" disabled>
            <el-button slot="append" type="primary" icon="el-icon-search" @click="queryMaterialData"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item class="no-warn-item" label="工程整车号:" prop="vehicleNo">
          <el-input
            v-model="formModel.vehicleNo"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('material_vehicle_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('material_vehicle_clear')" plain @click="clearCondition">清除</el-button>
            <el-button type="primary" v-if="hasPermission('material_vehicle_add')" plain @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData"  :columns="columns">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span class="hey_tools_btn" v-if="hasPermission('material_vehicle_edit')" @click="handleEdit(row)">编辑</span>
            <span class="hey_tools_btn" v-if="hasPermission('material_vehicle_del')" @click="handleDelete(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="工程号与整车物料号信息"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <material-vehicle-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>
    <el-dialog
      v-dialogDrag
      v-if="showMaterialData"
      :close-on-click-modal="false"
      title="物料主数据"
      :visible.sync="showMaterialData"
      width="90%"
      append-to-body
    >
      <material-data-dialog :edit-data="editData" @queryMaterialDataSuc="queryMaterialDataSuc" />
    </el-dialog>

  </div>
</template>

<script>

  export default {
    name: 'MaterialVehicleList',
    components: {
      MaterialDataDialog: () => import('@/views/dialog/material-data-dialog'),
      MaterialVehicleMnt: () => import('./material-vehicle-mnt')
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        showMaterialData:false,
        operType: '',
        editData: {},
        tableData:[],
        moduleOptions:[],
        formModel: {
          materialNo: '',
          vehicleNo: '',
          isDelete: '0'
        },
        columns: [
          { title: '整车物料号', key: 'materialNo'},
          { title: '车型', key: 'productTypeKey',clcd:'key_product_type'},
          { title: '工程整车号', key: 'vehicleNo'},
          { title: '工程整车描述', key: 'vehicleDesc'},
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ]
      }
    },
    computed: {

    },
    mounted() {

    },
    methods: {
      clearCondition(){
        this.resetObj(this.formModel)
        this.formModel.isDelete = '0'
      },
      queryMaterialData(){
        this.editData.materialTypeKey = 'car'
        this.showMaterialData = true
      },
      queryMaterialDataSuc(data){
        this.formModel.materialNo = data.materialNo
      },
      queryList() {
        this.$refs.table.query('/trBasMaterialVehicle/queryTrBasMaterialVehicle', this.formModel, '', false)
      },
      handleAdd() {
        this.operType = 'add'
        this.dialogVisible = true
      },
      handleEdit(row) {
        this.dialogVisible = true
        this.operType = 'edit'
        this.editData = row || {}
      },
      handleDelete(row) {
        this.$sure('确认删除？', _ => {
          this.post('/trBasMaterialVehicle/maintainTrBasMaterialVehicle', { rcrdId: row.rcrdId,operateType:'03'}).then(_ => {
            this.$info('删除成功', this.queryList)
          })
        })
      }
    }
  }
</script>


